package ar.edu.itba.it.paw.web.component;

import org.apache.wicket.behavior.SimpleAttributeModifier;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.panel.Panel;
import org.apache.wicket.model.AbstractReadOnlyModel;
import org.apache.wicket.model.CompoundPropertyModel;
import org.apache.wicket.model.IModel;
import org.apache.wicket.model.PropertyModel;

import ar.edu.itba.it.paw.domain.EntityModel;
import ar.edu.itba.it.paw.domain.Product;

public class ProductDetailPanel extends Panel {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	public ProductDetailPanel(String id, Product product) {
		super(id);
		
		setDefaultModel(new CompoundPropertyModel<Product>(new EntityModel<Product>(Product.class,product)));
		
		add(new Label("seller",new PropertyModel<String>(getDefaultModel(), "owner.username")).add(new SimpleAttributeModifier("style", "")));
		add(new Label("name").add(new SimpleAttributeModifier("style", "")));
		add(new Label("description").add(new SimpleAttributeModifier("style", "")));
		add(new Label("category",new PropertyModel<String>(getDefaultModel(), "category.name")).add(new SimpleAttributeModifier("style", "")));
		add(new PriceLabel("price",new PropertyModel<Double>(getDefaultModel(),"price")).add(new SimpleAttributeModifier("style", "")));
		add(new Label("quantity").add(new SimpleAttributeModifier("style", "")));
		add(new Label("state", new ProductStateModel((IModel<Product>)getDefaultModel())).add(new SimpleAttributeModifier("style", "")));
	}
	
	public class ProductStateModel extends AbstractReadOnlyModel<String> {
		
		/**
		 * 
		 */
		private static final long serialVersionUID = 1L;
		IModel<Product> product;
		
		public ProductStateModel(IModel<Product> product){
			this.product = product;
		}
		
		@Override
		public String getObject() {
			return product.getObject().getState() == true ? "Nuevo" : "Usado"; 
		}
		
	}

}
